export class AudioTips { //音乐
	constructor(src = "") {
		console.log("音频已加载")
		return {
			audio: this.load(src),
			currentTime: this.currentTime,
			play: this.play,
			pause: this.pause
		}
	}
	load(src) {
		let audio = document.createElement("audio");
		// audio.setAttribute("autoplay", false);
		audio.setAttribute("loop", true);
		audio.setAttribute("preload", "auto");
		audio.setAttribute("src", src);
		audio.volume = 1;
		return audio;
	}
	play() {
		this.currentTime(0);
		if (this.audio.paused) {
			this.audio.play();
		}
	}
	pause() {
		this.audio.pause();
	}
	currentTime(numb) {
		this.audio.currentTime = numb
	}
}
export class FwbSocket {
	constructor(url = "") {
		this.status = 1; //可行
	}
	load(url) {
		this.ws = new WebSocket(url);
		this.ws.onopen = res => {
			console.log("WebSocket连接成功");
			this.ws.send('WebSocket连接成功');
		}
		this.ws.onerror = err => {
			console.error("WebSocket连接出错:", err)
		};
		this.ws.onclose = () => {
			if (this.status != 1) return console.log("ws 已关闭，不在连接，请重新登录");
			console.log("WebSocket连接已关闭,重新连接");
			this.open(url);
		};
		this.ws.onmessage = res => {
			this.message(res);
		};
	}
	close() {
		this.status = 2;
		this.ws.close();
	}
	open(url) {
		// console.log("ws连接：",url)
		this.status = 1;
		this.load(url);
	}
	message() {}
	send(msg) {
		this.ws.send(msg);
		console.log("已发送内容：", msg)
	}
};
